// src/api/comment.js
import request from '@/utils/request'

// 获取待审核评论列表
export function getPendingComments(params) {
  return request({
    url: '/api/v1/admin/comments/pending',
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 10
    }
  })
}

// 审核评论
export function auditComment(commentId, status, remark) {
  return request({
    url: `/api/v1/admin/comments/${commentId}/audit`,
    method: 'post',
    params: { status, remark }
  })
}

// 批量审核评论
export function batchAuditComments(data) {
  return request({
    url: '/api/v1/admin/comments/batch-audit',
    method: 'post',
    data
  })
}

// 获取评论举报列表
export function getCommentReports(params) {
  return request({
    url: '/api/v1/admin/comments/reports',
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 10
    }
  })
}

// 添加敏感词
export function addSensitiveWord(data) {
  return request({
    url: '/api/v1/admin/comments/sensitive-words',
    method: 'post',
    data
  })
}

// 删除敏感词
export function deleteSensitiveWord(id) {
  return request({
    url: `/api/v1/admin/comments/sensitive-words/${id}`,
    method: 'delete'
  })
}

// ==================== 商家评论管理 ====================

// 获取商品评论列表
export function getProductComments(productId, params) {
  return request({
    url: `/api/v1/merchant/comments/product/${productId}`,
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 10
    }
  })
}

// 获取商家所有商品的评论列表
export function getMerchantComments(params) {
  return request({
    url: '/api/v1/merchant/comments/all',
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 10,
      rating: params.rating,
      hasImage: params.hasImage,
      sortField: params.sortField || 'createTime',
      sortOrder: params.sortOrder || 'desc'
    }
  })
}


// 回复评论
export function replyComment(commentId, reply) {
  return request({
    url: `/api/v1/merchant/comments/${commentId}/reply`,
    method: 'post',
    params: { reply }
  })
}

// 批量回复评论
export function batchReplyComments(data) {
  return request({
    url: '/api/v1/merchant/comments/batch-reply',
    method: 'post',
    data
  })
}

// 获取评论统计
export function getCommentStatistics(productId) {
  return request({
    url: `/api/v1/merchant/comments/statistics/${productId}`,
    method: 'get'
  })
}

// 获取评论趋势
export function getCommentTrend(productId, days = 7) {
  return request({
    url: `/api/v1/merchant/comments/trend/${productId}`,
    method: 'get',
    params: { days }
  })
}

// 导出评论
export function exportComments(productId) {
  return request({
    url: `/api/v1/merchant/comments/export/${productId}`,
    method: 'get',
    responseType: 'blob'
  })
}

// 创建回复模板
export function createReplyTemplate(data) {
  return request({
    url: '/api/v1/merchant/comments/template',
    method: 'post',
    data
  })
}

// 更新回复模板
export function updateReplyTemplate(id, data) {
  return request({
    url: `/api/v1/merchant/comments/template/${id}`,
    method: 'put',
    data
  })
}

// 删除回复模板
export function deleteReplyTemplate(id) {
  return request({
    url: `/api/v1/merchant/comments/template/${id}`,
    method: 'delete'
  })
}

// 获取回复模板列表
export function getReplyTemplates() {
  return request({
    url: '/api/v1/merchant/comments/templates',
    method: 'get'
  })
}

// 检查商品是否已评价
export function checkProductReviewed(orderId, productId) {
  return request({
    url: '/api/v1/products/comments/check-reviewed',
    method: 'get',
    params: {
      orderId,
      productId
    }
  })
}
